home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / GL / snurb / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.2 KB  |  214 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *
  19.  * menu.c
  20.  *
  21.  */
  22.  
  23.  
  24. #include <stdio.h>
  25. #include <gl.h>
  26. #include "defines.h"
  27. #include "device.h"
  28. #include "event.h"
  29. #include "menu.h"
  30. #include "control.h"
  31. #include "nurb.h"
  32. #include "file.h"
  33. #include "snurb.h"
  34.  
  35.  
  36. /* Declare menus */
  37. static long snurb_menu;        
  38. static long tool_menu;        
  39. static long file_menu;
  40. static long primitive_menu;    
  41. static long options_menu;
  42.  
  43. extern int tool;
  44. extern int primitive;
  45.  
  46.  
  47. /* 
  48.  * Allocate and initialize the menus, then tell the event manager
  49.  * to watch for right mouse button clicks.
  50.  */
  51. void init_menus(void)
  52. {
  53.     snurb_menu = newpup();
  54.     tool_menu = newpup();
  55.     file_menu = newpup();
  56.     primitive_menu = newpup();
  57.     options_menu = newpup();
  58.  
  59.     set_defaults();
  60.     
  61.     add_event(ANY,  RIGHTMOUSE, DOWN, do_menus, NULL);
  62.     qdevice(RIGHTMOUSE);
  63. }
  64.  
  65.  
  66. /*
  67.  * Called by the event manager whenever the right mouse button is
  68.  * pressed.
  69.  */
  70. void do_menus(void)
  71. {
  72.     dopup(snurb_menu);
  73. }
  74.  
  75.  
  76. /*
  77.  * Rebuild the entire menu tree. Because menu items change based upon
  78.  * user input, sub-menus are rebuilt as necessary. Then the root menu
  79.  * is rebuilt using these chaned sub-menus.
  80.  */
  81. void remake_snurb_menu(void)
  82. {
  83.     freepup(snurb_menu);
  84.     snurb_menu = newpup();
  85.  
  86.     addtopup(snurb_menu, "Snurbs %t", 0L); /* title */
  87.     addtopup(snurb_menu, "Tools %m", tool_menu);
  88.     addtopup(snurb_menu, "Options %m", options_menu);
  89.     addtopup(snurb_menu, "File %m", file_menu); 
  90.     addtopup(snurb_menu, "Add primitive %l%m", primitive_menu);
  91.     addtopup(snurb_menu, "Group Objects %f", group);
  92.     addtopup(snurb_menu, "Ungroup Objects %l%f", ungroup);
  93.     addtopup(snurb_menu, "Select All Objects %f", select_all);
  94.     addtopup(snurb_menu, "Delete Selected Objects %f", delete_object);
  95.     addtopup(snurb_menu, "Set Defaults %f", set_defaults);
  96.     addtopup(snurb_menu, "Quit Snurb %f", quit);
  97. }
  98.  
  99.  
  100. /*
  101.  * Remakes the menu which giving control over the current tool.
  102.  */
  103. void remake_tool_menu(void)
  104. {
  105.     char menu_string[32];
  106.     
  107.     freepup(tool_menu);
  108.     tool_menu = newpup();
  109.  
  110.     addtopup(tool_menu, "Tool %t %F", change_tool);
  111.     
  112.     if (tool == MOVE_TOOL)
  113.         sprintf(menu_string, "->Move Tool %%x%d", MOVE_TOOL);
  114.     else
  115.         sprintf(menu_string, "  Move Tool %%x%d", MOVE_TOOL);
  116.     addtopup(tool_menu, menu_string, 0L);
  117.     
  118.     if (tool == EDIT_TOOL)
  119.         sprintf(menu_string, "->Edit Tool %%x%d", EDIT_TOOL);
  120.     else
  121.         sprintf(menu_string, "  Edit Tool %%x%d", EDIT_TOOL);
  122.     addtopup(tool_menu, menu_string, 0L);
  123.  
  124.     if (tool == SCALE_TOOL)
  125.         sprintf(menu_string, "->Scale Tool %%l%%x%d", SCALE_TOOL);
  126.     else
  127.         sprintf(menu_string, "  Scale Tool %%l%%x%d", SCALE_TOOL);
  128.     addtopup(tool_menu, menu_string, 0L);
  129.  
  130.     if (tool == SHARP_ZIP_TOOL)
  131.         sprintf(menu_string, "->Sharp Zip Tool %%x%d", SHARP_ZIP_TOOL);
  132.     else
  133.         sprintf(menu_string, "  Sharp Zip Tool %%x%d", SHARP_ZIP_TOOL);
  134.     addtopup(tool_menu, menu_string, 0L);
  135.     
  136.     if (tool == SMOOTH_ZIP_TOOL)
  137.         sprintf(menu_string, "->Smooth Zip Tool %%x%d", SMOOTH_ZIP_TOOL);
  138.     else
  139.         sprintf(menu_string, "  Smooth Zip Tool %%x%d", SMOOTH_ZIP_TOOL);
  140.     addtopup(tool_menu, menu_string, 0L);
  141.     
  142.     if (tool == ROUND_ZIP_TOOL)
  143.         sprintf(menu_string, "->Round Zip Tool %%l%%x%d", ROUND_ZIP_TOOL);
  144.     else
  145.         sprintf(menu_string, "  Round Zip Tool %%l%%x%d", ROUND_ZIP_TOOL);
  146.     addtopup(tool_menu, menu_string, 0L);
  147.     
  148.     if (tool == UNZIP_TOOL)
  149.         sprintf(menu_string, "->Unzip Tool %%x%d", UNZIP_TOOL);
  150.     else
  151.         sprintf(menu_string, "  Unzip Tool %%x%d", UNZIP_TOOL);
  152.     addtopup(tool_menu, menu_string, 0L);
  153. }
  154.  
  155.  
  156.  
  157. /* Remakes the options menu, which includes some of the above menus as
  158.  * sub-menus and is itself a sub-menu to the root menu.
  159.  */
  160. void remake_options_menu(void)
  161. {
  162.     freepup(options_menu);
  163.     options_menu = newpup();
  164.  
  165.     addtopup(options_menu, "Options %t", 0L);
  166.  
  167.     addtopup(options_menu, "Invert Selected Objects %f", invert_objects);
  168.     addtopup(options_menu, "Set Pixel Tolerance %f", change_tolerance);
  169. }
  170.  
  171.  
  172. void remake_file_menu(void)
  173. {
  174.     freepup(file_menu);
  175.     file_menu = newpup();
  176.  
  177.     addtopup(file_menu, "File %t", 0L);
  178.  
  179.     addtopup(file_menu, "Load /tmp/junk.snb %f", load_file);
  180.     addtopup(file_menu, "Save /tmp/junk.snb %f", save_file);
  181. }
  182.  
  183.  
  184.  
  185. void remake_primitive_menu(void)
  186. {
  187.     char menu_string[32];
  188.     
  189.     freepup(primitive_menu);
  190.     primitive_menu = newpup();
  191.  
  192.     addtopup(primitive_menu, "Primitives %t %F", add_primitive);
  193.  
  194.     sprintf(menu_string, "Plane %%x%d", PLANE);
  195.     addtopup(primitive_menu, menu_string, 0L);
  196.     
  197.     sprintf(menu_string, "Cube %%x%d", CUBE);
  198.     addtopup(primitive_menu, menu_string, 0L);
  199.     
  200.     sprintf(menu_string, "Teapot %%x%d", TEAPOT);
  201.     addtopup(primitive_menu, menu_string, 0L);
  202.  
  203.     
  204. }
  205.  
  206. void remake_all_menus()
  207. {
  208.     remake_tool_menu();
  209.     remake_options_menu();
  210.     remake_file_menu();
  211.     remake_primitive_menu();
  212.     remake_snurb_menu();
  213. };
  214.